package com.chenchao.javabase;

/**
 * @coding : utf-8
 * @Time : 2020/11/6 14:17
 * @Author : chenchao
 * @File : java运算符.java
 * @Software: IntelliJ IDEA
 */
public class java运算符 {
    public static void main(String[] args) {
        int a1=10;
        int a2=15;
        short a3=20;
        byte a4=5;
        //算术运算符
        System.out.println(a1 + a2);
        System.out.println(a1 - a2);
        System.out.println(a1 * a2);
        System.out.println(a1 / (double)a2);
        System.out.println(a2 % a3);
        System.out.println(a3 + a4);
        //a3+a4类型为int,尽管都是低于int,运算后会自动转
        // 如果有long或者float和double也会向上转

        //++自增
        int a=3;
        int b=a++;//先赋值，再自增
        System.out.println(a);//4
        int c=++a;//先赋值，再自减
        System.out.println(a);//5
        System.out.println(b);//3
        System.out.println(c);//5

        //关系运算符
        System.out.println(a1 > a2);
        System.out.println(a1 != a2);
        System.out.println(a1<a2);
        System.out.println(a1==a2);

        //逻辑运算符
        boolean b1=true;
        boolean b2=true;
        System.out.println(b1 && b2);
        System.out.println(b1 || b2);
        System.out.println(!(b1 && b2));
        //如果前面已经可以判断真假会短路

        //位运算
        int g1=3;//011
        int g2=5;//101
        System.out.println(g1 & g2);//与001  1
        System.out.println(g1 | g2);//或111  7
        System.out.println(g1 ^ g2);//异或110 6
        System.out.println(~ g2);//非010 -6
        System.out.println(g1 << 2);//高位移动01100 12
        //<<n 相当于*2的n次方

        //赋值运算符
        int y=1;
        int bp=9;
        System.out.println(y += bp);//10
        System.out.println(y -= bp);//1

        //+ 字符串连接符
        System.out.println(a + b);//5+3=8,int
        System.out.println(""+a + b);//53,string
        System.out.println(a + b+"");//先算加减，再拼接，String
        //+出现String会把后面的运算转成字符串连接

        //条件运算符:三目运算符
        int score=80;
        System.out.println(score > 60 ? "及格" : "不及格");//及格

    }
}
